package com.example.finalexamcovid_19situations;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class yvJia extends AppCompatActivity {

    Button b1,b2;
    EditText et;
    static TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yv_jia);


        et=(EditText)findViewById(R.id.editTextTextPersonName);
        b1=(Button)findViewById(R.id.button);
        b2=(Button)findViewById(R.id.button10);
        textView=(TextView)findViewById(R.id.textView);
        b1.setOnClickListener(new mclick());
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(yvJia.this,wuZiXuan1.class);
                startActivity(intent);
            }
        });
    }

    class mclick implements View.OnClickListener {
        public void onClick(View v) {
            Intent intent =new Intent();
            intent.setAction("abc");
            Bundle bundle=new Bundle();
            bundle.putString("hello",et.getText().toString());
            intent.putExtras(bundle);

            //Android 8之后需要setComponent才能收到广播消息，解决方法：
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
                //前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
                intent.setComponent(new ComponentName("com.example.finalexamcovid_19situations",
                        "com.example.finalexamcovid_19situations.YvJiaReceiver"));
            }

            sendBroadcast(intent);
            b2.setVisibility(View.VISIBLE);
        }
    }
}